/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.codeplex.boomships.Common;

import java.io.Serializable;
import java.util.List;
/**
 *
 * @author fleischer
 */
public class Board implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    private Player player;
    private List<BattleShip> lstShips;
    private List<Cell> lstTakenPositions;

    /**
     * @return the player
     */
    public Player getPlayer() {
        return player;
    }

    /**
     * @param player the player to set
     */
    public void setPlayer(Player player) {
        this.player = player;
    }

    /**
     * @return the lstShips
     */
    public List<BattleShip> getLstShips() {
        return lstShips;
    }

    /**
     * @param lstShips the lstShips to set
     */
    public void setLstShips(List<BattleShip> lstShips) {
        this.lstShips = lstShips;
    }

    
    public Board(){
    	//Se agregan los portaaviones.
    	for(int i = 0; i< Constants.CARRIERS_COUNT; i++){
    		//Se crea la nueva nave:
    		BattleShip p = new Carrier(lstTakenPositions);
    		//Se agrega a la lista de naves del tablero.
    		this.lstShips.add(p);
    		//Se agregan las posiciones ocupadas por la misma a la lista lstTakenPositions.
    		addTakenPositions(p);
    	}
    	//Se agregan los buques.
    	for(int i = 0; i< Constants.SHIPS_COUNT; i++){
    		//Se crea la nueva nave:
    		BattleShip s = new Ship(lstTakenPositions);
    		//Se agrega a la lista de naves del tablero.
    		this.lstShips.add(s);
    		//Se agregan las posiciones ocupadas por la misma a la lista lstTakenPositions.
    		addTakenPositions(s);
    	}
    	//Se agregan las lanchas.
    	for(int i = 0; i< Constants.BOATS_COUNT; i++){
    		//Se crea la nueva nave:
    		BattleShip b = new Boat(lstTakenPositions);
    		//Se agrega a la lista de naves del tablero.
    		this.lstShips.add(b);
    		//Se agregan las posiciones ocupadas por la misma a la lista lstTakenPositions.
    		addTakenPositions(b);
    	}
    }
    //Recibe como parametro una instancia de la clase BattleShip y agrega sus posiciones definidas a la lista de 
    //posiciones ocupadas.
    private void addTakenPositions(BattleShip bShip){
    	for(Cell c: bShip.lstCells){
    		this.lstTakenPositions.add(c);
    	}
    }
    
}
